package com.example.module_hp_white_noise.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import com.example.module_hp_white_noise.R;
import com.example.module_hp_white_noise.base.BaseUtils;
import com.example.module_hp_white_noise.entity.HpWhiteNoiseEntity1;

import java.util.List;

public class HpWhiteNoisePage1Adapter extends BaseQuickAdapter<HpWhiteNoiseEntity1, BaseViewHolder> {
    public HpWhiteNoisePage1Adapter() {
        super(R.layout.item_hp_white_noise_page1);
    }
    @Override
    protected void convert(BaseViewHolder helper, HpWhiteNoiseEntity1 item) {
        helper.setText(R.id.item_title,item.getTitle());
        helper.setText(R.id.item_describe,item.getDescribe());
        ImageView view = helper.getView(R.id.item_img);
        //设置图片等高
        ViewGroup.LayoutParams parm = view.getLayoutParams();
        int screenWidth = BaseUtils.getScreenWidth(view.getContext());
        parm.height = screenWidth/2-BaseUtils.dip2px(view.getContext(),27.5);
        view.setLayoutParams(parm);
        int imgUrl = view.getContext().getResources().getIdentifier(item.getImgUrl(),"drawable",view.getContext().getPackageName());
        //Log.e("资源id", String.valueOf(imgUrl));
        Glide.with(view.getContext()).load(imgUrl).apply(new RequestOptions().centerCrop().bitmapTransform(new RoundedCorners(20))).into(view);
        if(item.getTags()!=null){
            int [] textView = {R.id.item_tag1,R.id.item_tag2,R.id.item_tag3};
            String [] arr = item.getTags().split(",");
            for(int i=0;i<arr.length;i++){
                helper.setText(textView[i],arr[i]);
                helper.setVisible(textView[i],true);
            }
        }
    }
}
